//
//  BasicViewController.m
//  xpkc
//
//  Created by TopSage on 15/9/29.
//  Copyright (c) 2015年 TopSage. All rights reserved.
//

#import "BasicViewController.h"

@interface BasicViewController ()

@end

@implementation BasicViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        //tabbar颜色设置
        [self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                 GreenColor, NSForegroundColorAttributeName,
                                                 nil] forState:UIControlStateSelected];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = BGColor;
    if (IsIOS7) {
        //设置导航栏
        [self setEdgesForExtendedLayout:UIRectEdgeNone];
    }
    [self creatNavigationItem];
    if (IsIOS7) {
        //自定义导航栏按钮导致手势返回失效 可做如下设置
        if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
            self.navigationController.interactivePopGestureRecognizer.delegate = nil;
        }
    }
}

- (void)creatNavigationItem{
    UIImage *image = [UIImage imageNamed:@"back1"];
    if (IsIOS7) {
        //设置图片的渲染模式   UIImageRenderingModeAlwaysOriginal是声明图片按原来的样子显示
        image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithImage:image style:UIBarButtonItemStyleBordered target:self action:@selector(backToLastView)];
    self.navigationItem.leftBarButtonItem = backItem;
}

- (void)backToLastView{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewWillAppear:(BOOL)animated{
    //设置状态条的方向  UIInterfaceOrientationPortrait为正常方向
    [[UIApplication sharedApplication]setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
    //屏幕旋转的设置
    [[UIDevice currentDevice]
     setValue:[NSNumber
               numberWithInteger:UIInterfaceOrientationPortrait]
     forKey:@"orientation"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
